home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1994 January / PSL Monthly Shareware CD-ROM (Public Software Library) (January 1994).iso / games / dos / board / backgam.com / IBMUTILS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1979-11-30  |  4.5 KB  |  201 lines

  1. /****************************************************************/
  2. /*                                */
  3. /* ibmutils                            */
  4. /*                                */
  5. /* These are routines that are specific to the PC. Mostly, this    */
  6. /* involves the screen addressing functions. The C86 compiler    */
  7. /* has a kind of trickey way to do direct video I/O, but if you    */
  8. /* do the writes into the adapter card yourself, then you get    */
  9. /* the traditional "PC flicker" that we all know.        */
  10. /*                                */
  11. /****************************************************************/
  12.  
  13. #include    <stdio.h>
  14. #include    "bkg.h"
  15.  
  16. struct    regval    {
  17.         int    ax, bx, cx, dx, si, di, ds, es;
  18.         };
  19.  
  20. /*P*/
  21. /****************************************************************/
  22. /*                                */
  23. /* write_at                            */
  24. /*                                */
  25. /* This function puts "string" at row "x" column "y" on the PC    */
  26. /* display. On a color monitor, the text shows up in "color".    */
  27. /* The caller can put a special byte called CTEOL in the string    */
  28. /* to indicate "clear to end of line". This is used so that the    */
  29. /* PC looks like a real machine (the Kaypro).            */
  30. /*                                */
  31. /****************************************************************/
  32.  
  33. write_at( x, y, string, color )
  34.  
  35. int    x, y;
  36. char    string[];
  37. int    color;
  38.  
  39.     {
  40.  
  41.     int        pos, other;
  42.     unsigned    word;
  43.     struct    regval    regs;
  44.  
  45.     for( pos = 0; string[ pos ]; pos++ )
  46.         if ( string[ pos ] == CTEOL )
  47.             {
  48.             crt_srcp( x, y + pos, 0 );
  49.             regs.ax = 0x0920;
  50.             regs.bx = ( color & 0x00ff );
  51.             regs.cx = ( 80 - ( y + pos ) );
  52.             sysint( 0x10, ®s, ®s );
  53.             y--; /* dec y to account for 1 character. */
  54.             }
  55.         else
  56.             {
  57.             crt_srcp( x, y + pos, 0 );
  58.             regs.ax = 0x0900 | ( string[ pos ] & 0x00ff );
  59.             regs.bx = ( color & 0x00ff );
  60.             regs.cx = 1;
  61.             sysint( 0x10, ®s, ®s );
  62.             }
  63.  
  64.     } /* write_at */
  65.  
  66. /*P*/
  67. /****************************************************************/
  68. /*                                */
  69. /* char_at                            */
  70. /*                                */
  71. /* This is just like "write_at" except it transmits bytes.    */
  72. /*                                */
  73. /****************************************************************/
  74.  
  75. char_at( x, y, data, color )
  76.  
  77. int    x, y;
  78. char    data;
  79. int    color;
  80.  
  81.     {
  82.  
  83.     struct    regval    regs;
  84.  
  85.     crt_srcp( x, y, 0 );
  86.  
  87.     if ( data == CTEOL )
  88.         {
  89.         regs.ax = 0x0920;
  90.         regs.bx = ( color & 0x00ff );
  91.         regs.cx = ( 80 - y );
  92.         sysint( 0x10, ®s, ®s );
  93.         }
  94.     else
  95.         {
  96.         regs.ax = 0x0900 | ( data & 0x00ff );
  97.         regs.bx = ( color & 0x00ff );
  98.         regs.cx = 1;
  99.         sysint( 0x10, ®s, ®s );
  100.         }
  101.  
  102.     } /* char_at */
  103. /*P*/
  104. /****************************************************************/
  105. /*                                */
  106. /* clear                            */
  107. /*                                */
  108. /* Should be self-apparent.                    */
  109. /*                                */
  110. /****************************************************************/
  111.  
  112. clear()
  113.     {
  114.  
  115.     crt_cls();
  116.  
  117.     }
  118.  
  119. /*P*/
  120. /****************************************************************/
  121. /*                                */
  122. /* cursor                            */
  123. /*                                */
  124. /* Turn off the cursor - the Kaypro can do it!            */
  125. /*                                */
  126. /****************************************************************/
  127.  
  128. cursor( on_off )
  129.  
  130. int    on_off;
  131.  
  132.     {
  133.  
  134.     /* I don't know if this can be done on the PC    */
  135.     /* other than writing directly to the video    */
  136.     /* controller chip - the hardware reference    */
  137.     /* says that that's not a good idea.        */
  138.  
  139.     } /* cursor */
  140.  
  141. /*P*/
  142. /****************************************************************/
  143. /*                                */
  144. /* raw_kbhit, raw_keyboard                    */
  145. /*                                */
  146. /* This function checks for a keyboard character without    */
  147. /* reading it in. The other reads a byte from the keyboard w/o    */
  148. /* doing an echo to the terminal.                */
  149. /*                                */
  150. /****************************************************************/
  151.  
  152. raw_kbhit()
  153.  
  154.     {
  155.  
  156.     return( ( key_scan() == -1 ) ? FALSE : TRUE );
  157.  
  158.     } /* my_kbhit */
  159.  
  160. raw_keyboard()
  161.  
  162.     {
  163.  
  164.     unsigned int    scan_n_char, cast;
  165.     unsigned char    ch;
  166.  
  167.     scan_n_char = key_getc();
  168.     ch = ( scan_n_char & 0x00ff );
  169.     cast = ch;
  170.     cast &= 0x00ff;    /* Make absolutely sure...    */
  171.  
  172.     return( cast );
  173.  
  174.     }
  175.  
  176. /*P*/
  177. /****************************************************************/
  178. /*                                */
  179. /* srand1                            */
  180. /*                                */
  181. /* On the Kaypro BDS C, which is not at all standard, this    */
  182. /* function is included in the RTL. Here, we display "str" and    */
  183. /* start counting. When a key is pressed, it's time to seed the    */
  184. /* random number generator.                    */
  185. /*                                */
  186. /****************************************************************/
  187.  
  188. srand1( str )
  189.  
  190. char    *str;
  191.  
  192.     {
  193.  
  194.     unsigned int    seed;
  195.  
  196.     printf( "%s", str );
  197.     for( seed = 0; ! raw_kbhit(); seed++ );
  198.     srand( seed );
  199.  
  200.     } /* srand1 */
  201.